001 /* 002 * Copyright 2006 Stephen McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package net.dpml.http; 017 018 import net.dpml.logging.Logger; 019 020 /** 021 * Servlet context handler. 022 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 023 * @version 0.0.3 024 */ 025 public class ServletContextHandler extends org.mortbay.jetty.handler.ContextHandler 026 { 027 /** 028 * HTTP static resource vontext handler parameters. 029 */ 030 public interface Context extends ContextHandlerContext 031 { 032 /** 033 * Get the http context resource base. The value may contain symbolic 034 * property references and should resolve to a local directory. 035 * 036 * @return the resource base 037 */ 038 String getResourceBase(); 039 040 /** 041 * Get the array of servlet holders. 042 * @param holders the default value 043 * @return the resolved value 044 */ 045 ServletHolder[] getServletHolders( ServletHolder[] holders ); 046 047 /** 048 * Get the array of servlet name to path mappings. 049 * @param entries the default value 050 * @return the resolved array of name to path mappings 051 */ 052 ServletEntry[] getServletEntries( ServletEntry[] entries ); 053 } 054 055 private int m_priority = 0; 056 057 /** 058 * Creation of a new servlet context handler. 059 * @param logger the assigned logging channel 060 * @param context the deployment context 061 * @exception Exception if an instantiation error occurs 062 */ 063 public ServletContextHandler( Logger logger, Context context ) throws Exception 064 { 065 super(); 066 067 ContextHelper helper = new ContextHelper( logger ); 068 helper.contextualize( this, context ); 069 070 String base = context.getResourceBase(); 071 super.setResourceBase( base ); 072 073 ServletHolder[] holders = context.getServletHolders( new ServletHolder[0] ); 074 ServletEntry[] entries = context.getServletEntries( new ServletEntry[0] ); 075 ServletHandler handler = new ServletHandler( holders, entries ); 076 super.setHandler( handler ); 077 } 078 }